package com.neusoft.controller;

import com.neusoft.po.CommonResult;
import com.neusoft.po.Food;
import com.neusoft.service.FoodService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/FoodController")
@RefreshScope       //开启动态刷新
public class FoodController {

    @Autowired
    private FoodService foodService;

    @GetMapping("/listFoodByBusinessId/{businessId}")
    public CommonResult<List<Food>> listFoodByBusinessId(@PathVariable("businessId") Integer businessId)
            throws Exception {
        List<Food> list = foodService.listFoodByBusinessId(businessId);
        return new CommonResult<>(200, "success", list);
    }

    @GetMapping("/getFoodById/{businessId}/{foodId}")
    public CommonResult<Food> getFoodById(@PathVariable("businessId") Integer businessId,
                                          @PathVariable("foodId") Integer foodId) throws Exception {
        Food food = foodService.getFoodById(foodId);
        return new CommonResult<>(200, "success", food);
    }

    @DeleteMapping("/deleteFoodById/{BusinessId}/{foodId}")
    public CommonResult<Integer> deleteFoodById(@PathVariable("BusinessId") Integer BusinessId,@PathVariable("foodId") Integer foodId) throws Exception {
        return new CommonResult<>(200, "success", foodService.deleteFoodById(BusinessId, foodId));
    }

    @PutMapping("/updateFoodById/{food.foodId}/{food.foodName}/{foodExplain}/{food.foodPrice}")
    public CommonResult<Integer> updateFoodById(@PathVariable Food food) throws Exception {
        return new CommonResult<>(200, "success", foodService.updateFoodById(food));
    }
}